package com.magirard.project.entity 
{
	import com.magirard.project.shader.IBaseShader;
	import com.magirard.project.texture.TextureManager;
	import com.magirard.project.util.ObjParser;
	import flash.display.Bitmap;
	import flash.display3D.Context3D;
	import flash.display3D.Context3DVertexBufferFormat;
	import flash.display3D.textures.Texture;
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	/**
	 * ...
	 * @author Marc Andre Girard
	 */
	public class StaticMesh 
	{
		private var mDiffuseBitmap:Bitmap;
		private var mShader:IBaseShader;
		private var mDiffuseTexture:Texture;
		private var mModelMatrix:Matrix3D;
		private var mContext3d:Context3D;
		private var mMyMesh:ObjParser;
		
		
		public function StaticMesh(aContext3d:Context3D,aMeshData:ObjParser, aDiffuse:Texture) 
		{
			mContext3d = aContext3d;
			mMyMesh = aMeshData
			mDiffuseTexture = aDiffuse;
			mModelMatrix = new Matrix3D();
			mModelMatrix.identity();
		}
		
		public function Render():void
		{
			mContext3d.setVertexBufferAt(0, mMyMesh.positionsBuffer, 0, Context3DVertexBufferFormat.FLOAT_3);
			mContext3d.setVertexBufferAt(1, mMyMesh.uvBuffer, 0, Context3DVertexBufferFormat.FLOAT_2);
			mContext3d.setVertexBufferAt(2, mMyMesh.colorsBuffer, 0, Context3DVertexBufferFormat.FLOAT_4);
			
			mContext3d.drawTriangles(mMyMesh.indexBuffer, 0, mMyMesh.indexBufferCount);	
		}
		
		public function get DiffuseTexture():Texture 
		{
			return mDiffuseTexture;
		}
		
		public function set DiffuseTexture(value:Texture):void 
		{
			mDiffuseTexture = value;
		}
		
		public function get Shader():IBaseShader 
		{
			return mShader;
		}
		
		public function set Shader(value:IBaseShader):void 
		{
			mShader = value;
		}
		
		public function get ModelMatrix():Matrix3D 
		{
			return mModelMatrix;
		}
		
		public function set ModelMatrix(value:Matrix3D):void 
		{
			mModelMatrix = value;
		}
		
		public function set Position(aPosition:Vector3D):void
		{
			mModelMatrix.position = aPosition;
		}
		
		public function get Position():Vector3D
		{
			return mModelMatrix.position;
		}
		
	}

}